using System;
using MoonFramework;
using MoonFramework.Test;

namespace Data.Bag
{

    /// <summary>
    /// 背包数据
    /// </summary>
    public class BagData
    {
        //格子中的物品
        public ItemData[] ItemDataList { get; protected set; }
        
        public BagData(){}
        public BagData(int itemDataCount)
        {
            ItemDataList = new ItemData[itemDataCount];
        }
        
        public void SetItem(int index, ItemData itemData) => ItemDataList[index] = itemData;
        public void RemoveItem(int index) => ItemDataList[index] = null;
    }
    
    /// <summary>
    /// 快捷栏数据
    /// </summary>
    public class ToolBarData : BagData
    {
        public ItemData WeaponSlotItemData { get; private set; }
        
        public ToolBarData(){}
        public ToolBarData(int itemDataCount) : base(itemDataCount) { }
        
        public void Init(ToolBarDataPro toolBarDataPro)
        {
            var itemsPro = toolBarDataPro.ItemDataList;
            ItemDataList = new ItemData[itemsPro.Count];
            for (int i = 0; i < ItemDataList.Length; i++)
            {
                ItemDataList[i] = ItemData.CreateItemData(itemsPro[i].ConfigID);
                ItemDataList[i].ItemTypeData = itemsPro[i].ItemTypeCase switch
                {
                    ItemDataPro.ItemTypeOneofCase.ConsumableData => new ItemConsumableItemData
                    {
                        Count = itemsPro[i].ConsumableData.Count
                    },
                    ItemDataPro.ItemTypeOneofCase.MaterialData => new ItemMaterialItemData
                    {
                        Count = itemsPro[i].MaterialData.Count
                    },
                    _ => throw new ArgumentOutOfRangeException()
                };
            }
            WeaponSlotItemData = new ItemData
            {
                ConfigID = toolBarDataPro.WeaponItemData.ConfigID,
                ItemTypeData = new ItemWeaponData
                {
                    Durability = toolBarDataPro.WeaponItemData.WeaponData.Durability
                }
            };
        }
        
        public void RemoveWeapon() => WeaponSlotItemData = null;
        public void SetWeapon(ItemData itemData) => WeaponSlotItemData = itemData;
    }
}